<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- ////////////////////////////////////////////////////////////////////
//        *********请尊重我的劳动成果,添加我的著作权*******                                                
//               CreatData: 2017-5-11                            
//               Java Web /:期末作业                            
//               Project: 宿舍管理系统                          
//               软件学院：  学号 ：16171201041                 
//               版权所有：http://allday.gq                     
//               官方邮箱：562015969@qq.com                    
///////////////////////////////////////////////////////////////////// -->










<html>
  
  <head>
    <meta charset="utf-8">
    <title>Student-Log</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../css/global.css" media="all">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css"></head>
  
  <body>
    <blockquote class="layui-elem-quote">
      <a href="javascript:;" class="layui-btn layui-btn-small" id="add">
        <i class="fa fa-wrench" aria-hidden="true"></i>申请维修</a>
    </blockquote>
    <script type="text/javascript" src="../plugins/layui/layui.js"></script>
    <script>layui.config({
        base: '../js/'
      });
      layui.use(['form', 'laydate', 'paging'],
      function() {
        var $ = layui.jquery,
        paging = layui.paging(),
        layerTips = parent.layer === undefined ? layui.layer: parent.layer,
        //获取父窗口的layer对象
        layer = layui.layer,
        //获取当前窗口的layer对象
        laydate = layui.laydate,
        form = layui.form();

        //自定义验证规则
        form.verify({
          title: function(value) {
            if (value.length < 5) {
              return '标题至少得5个字符啊';
            }
          },
          pass: [/(.+){6,12}$/, '密码必须6到12位'],
          content: function(value) {
            layedit.sync(editIndex);
          }
        });

        //监听指定开关
        form.on('switch(switchTest)',
        function(data) {
          layer.msg('当前状态：' + (this.checked ? 'true': 'false'), {
            offset: '6px'
          });
          layer.tips('如果选择了退宿您将登录不上该网页', data.othis)
        });

        var addBoxIndex = -1;
        $('#add').on('click',
        function() {
          if (addBoxIndex !== -1) return;
          //本表单通过ajax加载 --以模板的形式，当然你也可以直接写在页面上读取
          $.get('edit-FixForm.html', null,
          function(form) {
            addBoxIndex = layer.open({
              type: 1,
              title: '添加表单',
              content: form,
              btn: ['保存', '取消'],
              shade: false,
              offset: ['100px', '30%'],
              area: ['600px', '400px'],
              zIndex: 19950924,
              maxmin: true,
              yes: function(index) {
                //触发表单的提交事件
                $('form.layui-form').find('button[lay-filter=edit]').click();
              },
              full: function(elem) {
                var win = window.top === window.self ? window: parent.window;
                $(win).on('resize',
                function() {
                  var $this = $(this);
                  elem.width($this.width()).height($this.height()).css({
                    top: 0,
                    left: 0
                  });
                  elem.children('div.layui-layer-content').height($this.height() - 95);
                });
              },
              success: function(layero, index) {
                //弹出窗口成功后渲染表单
                var form = layui.form();
                form.render();
                form.on('submit(edit)',
                function(data) {
                  console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                  console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                  //console.log(data.field) 
                  console.log(data.field)
                  //当前容器的全部表单字段，名值对形式：{name: value}
                  //调用父窗口的layer对象
                  layerTips.open({
                    title: '这里面是表单的信息',
                    type: 1,
                    content: JSON.stringify(data.field),
                    area: ['500px', '300px'],
                    btn: ['添加', '取消'],
                    yes: function(index, layero) { //11
                      if (window.XMLHttpRequest) {
                        // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
                        xmlhttp = new XMLHttpRequest();
                        console.log("success for 111");
                      } else {
                        // IE6, IE5 浏览器执行代码
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                        console.log("success for 222");

                      }
                      xmlhttp.onreadystatechange = function() {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                          console.log("success：context：：：" + xmlhttp.responseText);
                          layerTips.msg('添加成功');
                          layerTips.close(index);
                          location.reload(); //刷新

                        }
                      }
                      xmlhttp.open("GET", "https://api.i-meto.com/mecho", true);
                      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                      xmlhttp.send("encode=js-html&length=2" + JSON.stringify(data.field));
                      console.log("已发送");

                    } //11
                  });
                  //这里可以写ajax方法提交表单
                  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。									
                });
                //console.log(layero, index);
              },
              end: function() {
                addBoxIndex = -1;
              }
            });
          });
        });

      });</script>
  </body>

</html>